def retain_first_5000_lines(input_file, output_file):
    with open(input_file, 'r', encoding='utf-8') as f_in, open(output_file, 'w', encoding='utf-8') as f_out:
        for i, line in enumerate(f_in, start=1):
            if i <= 6000:
                f_out.write(line)
            else:
                break

            # 使用函数


retain_first_5000_lines('ratings2.dat', 'ratings4.dat')